package com.hdu.other.monotonyStack;

import java.io.*;

public class bigFishEatSmallFish {

    private static final int MAX_N = 100000;
    private static final int[] ARR = new int[MAX_N];
    private static final int[][] STACK = new int[MAX_N][2];
    private static int N;


    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        StreamTokenizer st = new StreamTokenizer(in);
        while ((st.nextToken() != StreamTokenizer.TT_EOF)) {
            N = ((int) st.nval);
            refresh();
            for (int i = 0; i < N; i++) {
                st.nextToken();
                ARR[i] = ((int) st.nval);
            }
            pw.println(turns());
        }

        pw.flush();
        pw.close();
        in.close();
    }

    public static int turns() {
        int r = 0;
        int ans = 0;
        for (int i = N - 1, curTurns; i >= 0; i--) {
            curTurns = 0;
            if (r == 0 || ARR[i] <= ARR[STACK[r - 1][0]]) {
                STACK[r][0] = i;
                STACK[r++][1] = curTurns;
            } else {
                while (r > 0 && ARR[i] > ARR[STACK[r - 1][0]]) {
                    curTurns = Math.max(curTurns + 1, STACK[r - 1][1]);
                    r--;
                }
                STACK[r][0] = i;
                STACK[r++][1] = curTurns;
            }
        }
        return ans;
    }

    static void refresh() {
        for (int i = 0; i < N; i++) {
            STACK[i][0] = 0;
            STACK[i][1] = 0;
        }
    }
}
